#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
const int N = 2e5 + 10;

LL n, f[N];

int main()
{
	cin >> n;
	LL prev = 0, ans = -1e5;
	for(int i = 1;i <= n;i ++)
	{
		LL x; cin >> x;
		f[i] = f[i - 1] + x;
		ans = max(ans, max(x, f[i] - prev));
		prev = min(prev, f[i]);
	}
	cout << ans << endl;
}